/******************************************************************************
 * Product: Adempiere ERP & CRM Smart Business Solution                       *
 * Copyright (C) 1999-2007 ComPiere, Inc. All Rights Reserved.                *
 * This program is free software, you can redistribute it and/or modify it    *
 * under the terms version 2 of the GNU General Public License as published   *
 * by the Free Software Foundation. This program is distributed in the hope   *
 * that it will be useful, but WITHOUT ANY WARRANTY, without even the implied *
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.           *
 * See the GNU General Public License for more details.                       *
 * You should have received a copy of the GNU General Public License along    *
 * with this program, if not, write to the Free Software Foundation, Inc.,    *
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.                     *
 * For the text or an alternative of this public license, you may reach us    *
 * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA        *
 * or via info@compiere.org or http://www.compiere.org/license.html           *
 *****************************************************************************/
/** Generated Model - DO NOT CHANGE */
package org.compiere.model;

import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Properties;
import java.util.logging.Level;

import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;

/** Generated Model for A_Asset
 *  @author Adempiere (generated) 
 *  @version Release 3.7.0LTS - $Id$ */
public class X_A_Asset extends PO implements I_A_Asset, I_Persistent 
{

	/**
	 *
	 */
	private static final long serialVersionUID = 20110831L;

    /** Standard Constructor */
    public X_A_Asset (Properties ctx, int A_Asset_ID, String trxName)
    {
      super (ctx, A_Asset_ID, trxName);
      /** if (A_Asset_ID == 0)
        {
			setA_Asset_Group_ID (0);
			setA_Asset_ID (0);
			setIsDepreciated (false);
			setIsDisposed (false);
			setIsFullyDepreciated (false);
// N
			setIsInPosession (false);
			setIsOwned (false);
			setM_AttributeSetInstance_ID (0);
			setName (null);
			setValue (null);
        } */
    }

    /** Load Constructor */
    public X_A_Asset (Properties ctx, ResultSet rs, String trxName)
    {
      super (ctx, rs, trxName);
    }

    /** AccessLevel
      * @return 3 - Client - Org 
      */
    protected int get_AccessLevel()
    {
      return accessLevel.intValue();
    }

    /** Load Meta Data */
    protected POInfo initPO (Properties ctx)
    {
      POInfo poi = POInfo.getPOInfo (ctx, Table_ID, get_TrxName());
      return poi;
    }

    public String toString()
    {
      StringBuffer sb = new StringBuffer ("X_A_Asset[")
        .append(get_ID()).append("]");
      return sb.toString();
    }

	/** Set Asset Creation Date.
		@param A_Asset_CreateDate Asset Creation Date	  */
	public void setA_Asset_CreateDate (Timestamp A_Asset_CreateDate)
	{
		set_ValueNoCheck (COLUMNNAME_A_Asset_CreateDate, A_Asset_CreateDate);
	}

	/** Get Asset Creation Date.
		@return Asset Creation Date	  */
	public Timestamp getA_Asset_CreateDate () 
	{
		return (Timestamp)get_Value(COLUMNNAME_A_Asset_CreateDate);
	}

	public org.compiere.model.I_A_Asset_Group getA_Asset_Group() throws RuntimeException
    {
		return (org.compiere.model.I_A_Asset_Group)MTable.get(getCtx(), org.compiere.model.I_A_Asset_Group.Table_Name)
			.getPO(getA_Asset_Group_ID(), get_TrxName());	}

	/** Set Asset Group.
		@param A_Asset_Group_ID 
		Group of Assets
	  */
	public void setA_Asset_Group_ID (int A_Asset_Group_ID)
	{
		if (A_Asset_Group_ID < 1) 
			set_Value (COLUMNNAME_A_Asset_Group_ID, null);
		else 
			set_Value (COLUMNNAME_A_Asset_Group_ID, Integer.valueOf(A_Asset_Group_ID));
	}

	/** Get Asset Group.
		@return Group of Assets
	  */
	public int getA_Asset_Group_ID () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_A_Asset_Group_ID);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	/** Set Asset.
		@param A_Asset_ID 
		Asset used internally or by customers
	  */
	public void setA_Asset_ID (int A_Asset_ID)
	{
		if (A_Asset_ID < 1) 
			set_ValueNoCheck (COLUMNNAME_A_Asset_ID, null);
		else 
			set_ValueNoCheck (COLUMNNAME_A_Asset_ID, Integer.valueOf(A_Asset_ID));
	}

	/** Get Asset.
		@return Asset used internally or by customers
	  */
	public int getA_Asset_ID () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_A_Asset_ID);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	/** Set Asset Reval. Date.
		@param A_Asset_RevalDate Asset Reval. Date	  */
	public void setA_Asset_RevalDate (Timestamp A_Asset_RevalDate)
	{
		set_Value (COLUMNNAME_A_Asset_RevalDate, A_Asset_RevalDate);
	}

	/** Get Asset Reval. Date.
		@return Asset Reval. Date	  */
	public Timestamp getA_Asset_RevalDate () 
	{
		return (Timestamp)get_Value(COLUMNNAME_A_Asset_RevalDate);
	}

	public org.compiere.model.I_AD_User getAD_User() throws RuntimeException
    {
		return (org.compiere.model.I_AD_User)MTable.get(getCtx(), org.compiere.model.I_AD_User.Table_Name)
			.getPO(getAD_User_ID(), get_TrxName());	}

	/** Set Usuario.
		@param AD_User_ID 
		User within the system - Internal or Business Partner Contact
	  */
	public void setAD_User_ID (int AD_User_ID)
	{
		if (AD_User_ID < 1) 
			set_Value (COLUMNNAME_AD_User_ID, null);
		else 
			set_Value (COLUMNNAME_AD_User_ID, Integer.valueOf(AD_User_ID));
	}

	/** Get Usuario.
		@return User within the system - Internal or Business Partner Contact
	  */
	public int getAD_User_ID () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_AD_User_ID);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	public org.compiere.model.I_A_Asset getA_Parent_Asset() throws RuntimeException
    {
		return (org.compiere.model.I_A_Asset)MTable.get(getCtx(), org.compiere.model.I_A_Asset.Table_Name)
			.getPO(getA_Parent_Asset_ID(), get_TrxName());	}

	/** Set Asset ID.
		@param A_Parent_Asset_ID Asset ID	  */
	public void setA_Parent_Asset_ID (int A_Parent_Asset_ID)
	{
		if (A_Parent_Asset_ID < 1) 
			set_Value (COLUMNNAME_A_Parent_Asset_ID, null);
		else 
			set_Value (COLUMNNAME_A_Parent_Asset_ID, Integer.valueOf(A_Parent_Asset_ID));
	}

	/** Get Asset ID.
		@return Asset ID	  */
	public int getA_Parent_Asset_ID () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_A_Parent_Asset_ID);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	/** Set Quantity.
		@param A_QTY_Current Quantity	  */
	public void setA_QTY_Current (BigDecimal A_QTY_Current)
	{
		set_Value (COLUMNNAME_A_QTY_Current, A_QTY_Current);
	}

	/** Get Quantity.
		@return Quantity	  */
	public BigDecimal getA_QTY_Current () 
	{
		BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_A_QTY_Current);
		if (bd == null)
			 return Env.ZERO;
		return bd;
	}

	/** Set Original Qty.
		@param A_QTY_Original Original Qty	  */
	public void setA_QTY_Original (BigDecimal A_QTY_Original)
	{
		set_Value (COLUMNNAME_A_QTY_Original, A_QTY_Original);
	}

	/** Get Original Qty.
		@return Original Qty	  */
	public BigDecimal getA_QTY_Original () 
	{
		BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_A_QTY_Original);
		if (bd == null)
			 return Env.ZERO;
		return bd;
	}

	/** Set Asset Depreciation Date.
		@param AssetDepreciationDate 
		Date of last depreciation
	  */
	public void setAssetDepreciationDate (Timestamp AssetDepreciationDate)
	{
		set_Value (COLUMNNAME_AssetDepreciationDate, AssetDepreciationDate);
	}

	/** Get Asset Depreciation Date.
		@return Date of last depreciation
	  */
	public Timestamp getAssetDepreciationDate () 
	{
		return (Timestamp)get_Value(COLUMNNAME_AssetDepreciationDate);
	}

	/** Set Asset Disposal Date.
		@param AssetDisposalDate 
		Date when the asset is/was disposed
	  */
	public void setAssetDisposalDate (Timestamp AssetDisposalDate)
	{
		set_Value (COLUMNNAME_AssetDisposalDate, AssetDisposalDate);
	}

	/** Get Asset Disposal Date.
		@return Date when the asset is/was disposed
	  */
	public Timestamp getAssetDisposalDate () 
	{
		return (Timestamp)get_Value(COLUMNNAME_AssetDisposalDate);
	}

	/** Set In Service Date.
		@param AssetServiceDate 
		Date when Asset was put into service
	  */
	public void setAssetServiceDate (Timestamp AssetServiceDate)
	{
		set_Value (COLUMNNAME_AssetServiceDate, AssetServiceDate);
	}

	/** Get In Service Date.
		@return Date when Asset was put into service
	  */
	public Timestamp getAssetServiceDate () 
	{
		return (Timestamp)get_Value(COLUMNNAME_AssetServiceDate);
	}

	public org.compiere.model.I_C_BPartner getC_BPartner() throws RuntimeException
    {
		return (org.compiere.model.I_C_BPartner)MTable.get(getCtx(), org.compiere.model.I_C_BPartner.Table_Name)
			.getPO(getC_BPartner_ID(), get_TrxName());	}

	/** Set Business Partner .
		@param C_BPartner_ID 
		Identifies a Business Partner
	  */
	public void setC_BPartner_ID (int C_BPartner_ID)
	{
		if (C_BPartner_ID < 1) 
			set_Value (COLUMNNAME_C_BPartner_ID, null);
		else 
			set_Value (COLUMNNAME_C_BPartner_ID, Integer.valueOf(C_BPartner_ID));
	}

	/** Get Business Partner .
		@return Identifies a Business Partner
	  */
	public int getC_BPartner_ID () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_C_BPartner_ID);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	public org.compiere.model.I_C_BPartner_Location getC_BPartner_Location() throws RuntimeException
    {
		return (org.compiere.model.I_C_BPartner_Location)MTable.get(getCtx(), org.compiere.model.I_C_BPartner_Location.Table_Name)
			.getPO(getC_BPartner_Location_ID(), get_TrxName());	}

	/** Set Partner Location.
		@param C_BPartner_Location_ID 
		Identifies the (ship to) address for this Business Partner
	  */
	public void setC_BPartner_Location_ID (int C_BPartner_Location_ID)
	{
		if (C_BPartner_Location_ID < 1) 
			set_Value (COLUMNNAME_C_BPartner_Location_ID, null);
		else 
			set_Value (COLUMNNAME_C_BPartner_Location_ID, Integer.valueOf(C_BPartner_Location_ID));
	}

	/** Get Partner Location.
		@return Identifies the (ship to) address for this Business Partner
	  */
	public int getC_BPartner_Location_ID () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_C_BPartner_Location_ID);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	public org.compiere.model.I_C_BPartner getC_BPartnerSR() throws RuntimeException
    {
		return (org.compiere.model.I_C_BPartner)MTable.get(getCtx(), org.compiere.model.I_C_BPartner.Table_Name)
			.getPO(getC_BPartnerSR_ID(), get_TrxName());	}

	/** Set BPartner (Agent).
		@param C_BPartnerSR_ID 
		Business Partner (Agent or Sales Rep)
	  */
	public void setC_BPartnerSR_ID (int C_BPartnerSR_ID)
	{
		if (C_BPartnerSR_ID < 1) 
			set_Value (COLUMNNAME_C_BPartnerSR_ID, null);
		else 
			set_Value (COLUMNNAME_C_BPartnerSR_ID, Integer.valueOf(C_BPartnerSR_ID));
	}

	/** Get BPartner (Agent).
		@return Business Partner (Agent or Sales Rep)
	  */
	public int getC_BPartnerSR_ID () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_C_BPartnerSR_ID);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	public org.compiere.model.I_C_Location getC_Location() throws RuntimeException
    {
		return (org.compiere.model.I_C_Location)MTable.get(getCtx(), org.compiere.model.I_C_Location.Table_Name)
			.getPO(getC_Location_ID(), get_TrxName());	}

	/** Set Address.
		@param C_Location_ID 
		Location or Address
	  */
	public void setC_Location_ID (int C_Location_ID)
	{
		if (C_Location_ID < 1) 
			set_Value (COLUMNNAME_C_Location_ID, null);
		else 
			set_Value (COLUMNNAME_C_Location_ID, Integer.valueOf(C_Location_ID));
	}

	/** Get Address.
		@return Location or Address
	  */
	public int getC_Location_ID () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_C_Location_ID);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}
	
	public org.compiere.model.I_A_Location getA_Location() throws RuntimeException
	{
		return (org.compiere.model.I_A_Location)MTable.get(getCtx(), org.compiere.model.I_A_Location.Table_Name)
				.getPO(getA_Location_ID(), get_TrxName()); }
	
	/**Set Location of Asset */
	public void setA_Location_ID (int A_Location_ID)
	{
		if(A_Location_ID < 1)
			set_Value(COLUMNNAME_A_Location_ID, null);
		else
			set_Value(COLUMNNAME_A_Location_ID, Integer.valueOf(A_Location_ID));
	}
	/** Get Location of Asset*/
	public int getA_Location_ID ()
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_A_Location_ID);
		if (ii == null)
			return 0;
		return ii.intValue();
	}

	public org.compiere.model.I_C_Project getC_Project() throws RuntimeException
    {
		return (org.compiere.model.I_C_Project)MTable.get(getCtx(), org.compiere.model.I_C_Project.Table_Name)
			.getPO(getC_Project_ID(), get_TrxName());	}

	/** Set Project.
		@param C_Project_ID 
		Financial Project
	  */
	public void setC_Project_ID (int C_Project_ID)
	{
		if (C_Project_ID < 1) 
			set_Value (COLUMNNAME_C_Project_ID, null);
		else 
			set_Value (COLUMNNAME_C_Project_ID, Integer.valueOf(C_Project_ID));
	}

	/** Get Project.
		@return Financial Project
	  */
	public int getC_Project_ID () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_C_Project_ID);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	/** Set Description.
		@param Description 
		Optional short description of the record
	  */
	public void setDescription (String Description)
	{
		set_Value (COLUMNNAME_Description, Description);
	}

	/** Get Description.
		@return Optional short description of the record
	  */
	public String getDescription () 
	{
		return (String)get_Value(COLUMNNAME_Description);
	}

	/** Set Guarantee Date.
		@param GuaranteeDate 
		Date when guarantee expires
	  */
	public void setGuaranteeDate (Timestamp GuaranteeDate)
	{
		set_Value (COLUMNNAME_GuaranteeDate, GuaranteeDate);
	}

	/** Get Guarantee Date.
		@return Date when guarantee expires
	  */
	public Timestamp getGuaranteeDate () 
	{
		return (Timestamp)get_Value(COLUMNNAME_GuaranteeDate);
	}

	/** Set Comment/Help.
		@param Help 
		Comment or Hint
	  */
	public void setHelp (String Help)
	{
		set_Value (COLUMNNAME_Help, Help);
	}

	/** Get Comment/Help.
		@return Comment or Hint
	  */
	public String getHelp () 
	{
		return (String)get_Value(COLUMNNAME_Help);
	}

	/** Set Depreciate.
		@param IsDepreciated 
		The asset will be depreciated
	  */
	public void setIsDepreciated (boolean IsDepreciated)
	{
		set_Value (COLUMNNAME_IsDepreciated, Boolean.valueOf(IsDepreciated));
	}

	/** Get Depreciate.
		@return The asset will be depreciated
	  */
	public boolean isDepreciated () 
	{
		Object oo = get_Value(COLUMNNAME_IsDepreciated);
		if (oo != null) 
		{
			 if (oo instanceof Boolean) 
				 return ((Boolean)oo).booleanValue(); 
			return "Y".equals(oo);
		}
		return false;
	}

	/** Set Disposed.
		@param IsDisposed 
		The asset is disposed
	  */
	public void setIsDisposed (boolean IsDisposed)
	{
		set_Value (COLUMNNAME_IsDisposed, Boolean.valueOf(IsDisposed));
	}

	/** Get Disposed.
		@return The asset is disposed
	  */
	public boolean isDisposed () 
	{
		Object oo = get_Value(COLUMNNAME_IsDisposed);
		if (oo != null) 
		{
			 if (oo instanceof Boolean) 
				 return ((Boolean)oo).booleanValue(); 
			return "Y".equals(oo);
		}
		return false;
	}

	/** Set Fully depreciated.
		@param IsFullyDepreciated 
		The asset is fully depreciated
	  */
	public void setIsFullyDepreciated (boolean IsFullyDepreciated)
	{
		set_ValueNoCheck (COLUMNNAME_IsFullyDepreciated, Boolean.valueOf(IsFullyDepreciated));
	}

	/** Get Fully depreciated.
		@return The asset is fully depreciated
	  */
	public boolean isFullyDepreciated () 
	{
		Object oo = get_Value(COLUMNNAME_IsFullyDepreciated);
		if (oo != null) 
		{
			 if (oo instanceof Boolean) 
				 return ((Boolean)oo).booleanValue(); 
			return "Y".equals(oo);
		}
		return false;
	}

	/** Set In Possession.
		@param IsInPosession 
		The asset is in the possession of the organization
	  */
	public void setIsInPosession (boolean IsInPosession)
	{
		set_Value (COLUMNNAME_IsInPosession, Boolean.valueOf(IsInPosession));
	}

	/** Get In Possession.
		@return The asset is in the possession of the organization
	  */
	public boolean isInPosession () 
	{
		Object oo = get_Value(COLUMNNAME_IsInPosession);
		if (oo != null) 
		{
			 if (oo instanceof Boolean) 
				 return ((Boolean)oo).booleanValue(); 
			return "Y".equals(oo);
		}
		return false;
	}

	/** Set Owned.
		@param IsOwned 
		The asset is owned by the organization
	  */
	public void setIsOwned (boolean IsOwned)
	{
		set_Value (COLUMNNAME_IsOwned, Boolean.valueOf(IsOwned));
	}

	/** Get Owned.
		@return The asset is owned by the organization
	  */
	public boolean isOwned () 
	{
		Object oo = get_Value(COLUMNNAME_IsOwned);
		if (oo != null) 
		{
			 if (oo instanceof Boolean) 
				 return ((Boolean)oo).booleanValue(); 
			return "Y".equals(oo);
		}
		return false;
	}

	/** Set Last Maintenance.
		@param LastMaintenanceDate 
		Last Maintenance Date
	  */
	public void setLastMaintenanceDate (Timestamp LastMaintenanceDate)
	{
		set_Value (COLUMNNAME_LastMaintenanceDate, LastMaintenanceDate);
	}

	/** Get Last Maintenance.
		@return Last Maintenance Date
	  */
	public Timestamp getLastMaintenanceDate () 
	{
		return (Timestamp)get_Value(COLUMNNAME_LastMaintenanceDate);
	}

	/** Set Last Note.
		@param LastMaintenanceNote 
		Last Maintenance Note
	  */
	public void setLastMaintenanceNote (String LastMaintenanceNote)
	{
		set_Value (COLUMNNAME_LastMaintenanceNote, LastMaintenanceNote);
	}

	/** Get Last Note.
		@return Last Maintenance Note
	  */
	public String getLastMaintenanceNote () 
	{
		return (String)get_Value(COLUMNNAME_LastMaintenanceNote);
	}

	/** Set Last Unit.
		@param LastMaintenanceUnit 
		Last Maintenance Unit
	  */
	public void setLastMaintenanceUnit (int LastMaintenanceUnit)
	{
		set_Value (COLUMNNAME_LastMaintenanceUnit, Integer.valueOf(LastMaintenanceUnit));
	}

	/** Get Last Unit.
		@return Last Maintenance Unit
	  */
	public int getLastMaintenanceUnit () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_LastMaintenanceUnit);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	public org.compiere.model.I_C_BPartner getLease_BPartner() throws RuntimeException
    {
		return (org.compiere.model.I_C_BPartner)MTable.get(getCtx(), org.compiere.model.I_C_BPartner.Table_Name)
			.getPO(getLease_BPartner_ID(), get_TrxName());	}

	/** Set Lessor.
		@param Lease_BPartner_ID 
		The Business Partner who rents or leases
	  */
	public void setLease_BPartner_ID (int Lease_BPartner_ID)
	{
		if (Lease_BPartner_ID < 1) 
			set_Value (COLUMNNAME_Lease_BPartner_ID, null);
		else 
			set_Value (COLUMNNAME_Lease_BPartner_ID, Integer.valueOf(Lease_BPartner_ID));
	}

	/** Get Lessor.
		@return The Business Partner who rents or leases
	  */
	public int getLease_BPartner_ID () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_Lease_BPartner_ID);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	/** Set Lease Termination.
		@param LeaseTerminationDate 
		Lease Termination Date
	  */
	public void setLeaseTerminationDate (Timestamp LeaseTerminationDate)
	{
		set_Value (COLUMNNAME_LeaseTerminationDate, LeaseTerminationDate);
	}

	/** Get Lease Termination.
		@return Lease Termination Date
	  */
	public Timestamp getLeaseTerminationDate () 
	{
		return (Timestamp)get_Value(COLUMNNAME_LeaseTerminationDate);
	}

	/** Set Life use.
		@param LifeUseUnits 
		Units of use until the asset is not usable anymore
	  */
	public void setLifeUseUnits (int LifeUseUnits)
	{
		set_Value (COLUMNNAME_LifeUseUnits, Integer.valueOf(LifeUseUnits));
	}

	/** Get Life use.
		@return Units of use until the asset is not usable anymore
	  */
	public int getLifeUseUnits () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_LifeUseUnits);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	/** Set Location comment.
		@param LocationComment 
		Additional comments or remarks concerning the location
	  */
	public void setLocationComment (String LocationComment)
	{
		set_Value (COLUMNNAME_LocationComment, LocationComment);
	}

	/** Get Location comment.
		@return Additional comments or remarks concerning the location
	  */
	public String getLocationComment () 
	{
		return (String)get_Value(COLUMNNAME_LocationComment);
	}

	/** Set Lot No.
		@param Lot 
		Lot number (alphanumeric)
	  */
	public void setLot (String Lot)
	{
		set_Value (COLUMNNAME_Lot, Lot);
	}

	/** Get Lot No.
		@return Lot number (alphanumeric)
	  */
	public String getLot () 
	{
		return (String)get_Value(COLUMNNAME_Lot);
	}

	public I_M_AttributeSetInstance getM_AttributeSetInstance() throws RuntimeException
    {
		return (I_M_AttributeSetInstance)MTable.get(getCtx(), I_M_AttributeSetInstance.Table_Name)
			.getPO(getM_AttributeSetInstance_ID(), get_TrxName());	}

	/** Set Attribute Set Instance.
		@param M_AttributeSetInstance_ID 
		Product Attribute Set Instance
	  */
	public void setM_AttributeSetInstance_ID (int M_AttributeSetInstance_ID)
	{
		if (M_AttributeSetInstance_ID < 0) 
			set_ValueNoCheck (COLUMNNAME_M_AttributeSetInstance_ID, null);
		else 
			set_ValueNoCheck (COLUMNNAME_M_AttributeSetInstance_ID, Integer.valueOf(M_AttributeSetInstance_ID));
	}

	/** Get Attribute Set Instance.
		@return Product Attribute Set Instance
	  */
	public int getM_AttributeSetInstance_ID () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_M_AttributeSetInstance_ID);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	public org.compiere.model.I_M_InOutLine getM_InOutLine() throws RuntimeException
    {
		return (org.compiere.model.I_M_InOutLine)MTable.get(getCtx(), org.compiere.model.I_M_InOutLine.Table_Name)
			.getPO(getM_InOutLine_ID(), get_TrxName());	}

	/** Set Shipment/Receipt Line.
		@param M_InOutLine_ID 
		Line on Shipment or Receipt document
	  */
	public void setM_InOutLine_ID (int M_InOutLine_ID)
	{
		if (M_InOutLine_ID < 1) 
			set_Value (COLUMNNAME_M_InOutLine_ID, null);
		else 
			set_Value (COLUMNNAME_M_InOutLine_ID, Integer.valueOf(M_InOutLine_ID));
	}

	/** Get Shipment/Receipt Line.
		@return Line on Shipment or Receipt document
	  */
	public int getM_InOutLine_ID () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_M_InOutLine_ID);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	public org.compiere.model.I_M_Locator getM_Locator() throws RuntimeException
    {
		return (org.compiere.model.I_M_Locator)MTable.get(getCtx(), org.compiere.model.I_M_Locator.Table_Name)
			.getPO(getM_Locator_ID(), get_TrxName());	}

	/** Set Locator.
		@param M_Locator_ID 
		Warehouse Locator
	  */
	public void setM_Locator_ID (int M_Locator_ID)
	{
		if (M_Locator_ID < 1) 
			set_Value (COLUMNNAME_M_Locator_ID, null);
		else 
			set_Value (COLUMNNAME_M_Locator_ID, Integer.valueOf(M_Locator_ID));
	}

	/** Get Locator.
		@return Warehouse Locator
	  */
	public int getM_Locator_ID () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_M_Locator_ID);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	public org.compiere.model.I_M_Product getM_Product() throws RuntimeException
    {
		return (org.compiere.model.I_M_Product)MTable.get(getCtx(), org.compiere.model.I_M_Product.Table_Name)
			.getPO(getM_Product_ID(), get_TrxName());	}

	/** Set Product.
		@param M_Product_ID 
		Product, Service, Item
	  */
	public void setM_Product_ID (int M_Product_ID)
	{
		if (M_Product_ID < 1) 
			set_ValueNoCheck (COLUMNNAME_M_Product_ID, null);
		else 
			set_ValueNoCheck (COLUMNNAME_M_Product_ID, Integer.valueOf(M_Product_ID));
	}

	/** Get Product.
		@return Product, Service, Item
	  */
	public int getM_Product_ID () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_M_Product_ID);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	/** Set Name.
		@param Name 
		Alphanumeric identifier of the entity
	  */
	public void setName (String Name)
	{
		set_Value (COLUMNNAME_Name, Name);
	}

	/** Get Name.
		@return Alphanumeric identifier of the entity
	  */
	public String getName () 
	{
		return (String)get_Value(COLUMNNAME_Name);
	}

    /** Get Record ID/ColumnName
        @return ID/ColumnName pair
      */
    public KeyNamePair getKeyNamePair() 
    {
        return new KeyNamePair(get_ID(), getName());
    }

	/** Set Next Maintenance.
		@param NextMaintenenceDate 
		Next Maintenance Date
	  */
	public void setNextMaintenenceDate (Timestamp NextMaintenenceDate)
	{
		set_Value (COLUMNNAME_NextMaintenenceDate, NextMaintenenceDate);
	}

	/** Get Next Maintenance.
		@return Next Maintenance Date
	  */
	public Timestamp getNextMaintenenceDate () 
	{
		return (Timestamp)get_Value(COLUMNNAME_NextMaintenenceDate);
	}

	/** Set Next Unit.
		@param NextMaintenenceUnit 
		Next Maintenance Unit
	  */
	public void setNextMaintenenceUnit (int NextMaintenenceUnit)
	{
		set_Value (COLUMNNAME_NextMaintenenceUnit, Integer.valueOf(NextMaintenenceUnit));
	}

	/** Get Next Unit.
		@return Next Maintenance Unit
	  */
	public int getNextMaintenenceUnit () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_NextMaintenenceUnit);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	/** Set Process Now.
		@param Processing Process Now	  */
	public void setProcessing (boolean Processing)
	{
		set_Value (COLUMNNAME_Processing, Boolean.valueOf(Processing));
	}

	/** Get Process Now.
		@return Process Now	  */
	public boolean isProcessing () 
	{
		Object oo = get_Value(COLUMNNAME_Processing);
		if (oo != null) 
		{
			 if (oo instanceof Boolean) 
				 return ((Boolean)oo).booleanValue(); 
			return "Y".equals(oo);
		}
		return false;
	}

	/** Set Quantity.
		@param Qty 
		Quantity
	  */
	public void setQty (BigDecimal Qty)
	{
		set_Value (COLUMNNAME_Qty, Qty);
	}

	/** Get Quantity.
		@return Quantity
	  */
	public BigDecimal getQty () 
	{
		BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_Qty);
		if (bd == null)
			 return Env.ZERO;
		return bd;
	}

	/** Set Serial No.
		@param SerNo 
		Product Serial Number 
	  */
	public void setSerNo (String SerNo)
	{
		set_Value (COLUMNNAME_SerNo, SerNo);
	}

	/** Get Serial No.
		@return Product Serial Number 
	  */
	public String getSerNo () 
	{
		return (String)get_Value(COLUMNNAME_SerNo);
	}

	/** Set Usable Life - Months.
		@param UseLifeMonths 
		Months of the usable life of the asset
	  */
	public void setUseLifeMonths (int UseLifeMonths)
	{
		set_Value (COLUMNNAME_UseLifeMonths, Integer.valueOf(UseLifeMonths));
	}

	/** Get Usable Life - Months.
		@return Months of the usable life of the asset
	  */
	public int getUseLifeMonths () 
	{
		/*Integer ii = (Integer)get_Value(COLUMNNAME_UseLifeMonths);
		if (ii == null)
			 return 0;
		return ii.intValue();*/
		StringBuffer sql =  new StringBuffer(
				"SELECT UseLifeMonths FROM A_Asset_Acct "
				+ " WHERE A_Asset_ID = "+ get_ID()
			    + " AND isActive = 'Y'");
			int iULM=0;
	        PreparedStatement pstmt = null;
	        ResultSet rs = null;
			pstmt = DB.prepareStatement (sql.toString(),null);
			rs = null;
			try {				
			  rs = pstmt.executeQuery();
			  while (rs.next()){
				  iULM = rs.getInt(1);
			  }
			} catch (Exception e) {
			  System.out.println("A_Asset_Acct. Asset ID: "+get_ID()+" "+e);
			} finally {
				DB.close(rs, pstmt);
			    rs = null; pstmt = null;
			}
			if (iULM>0) return iULM;
			
			sql.setLength(0);
			sql.append("SELECT UseLifeMonths FROM A_Asset_Group_Acct"
			    	+" WHERE A_Asset_Group_ID  = " +getA_Asset_Group_ID()	    		
			        +" AND isActive = 'Y'");
			pstmt = null;
			pstmt = DB.prepareStatement (sql.toString(),null);
			rs = null;
			try {				
				rs = pstmt.executeQuery();
			    while (rs.next()){
			    	iULM = rs.getInt(1);
			    }
			} catch (Exception e) {
				System.out.println("A_Asset_Group_Acct. Asset ID: "+get_ID()+" "+e);
			} finally {
				DB.close(rs, pstmt);
				rs = null; pstmt = null;
			}
			return iULM;	
	}

	/** Set Usable Life - Years.
		@param UseLifeYears 
		Years of the usable life of the asset
	  */
	public void setUseLifeYears (int UseLifeYears)
	{
		set_Value (COLUMNNAME_UseLifeYears, Integer.valueOf(UseLifeYears));
	}

	/** Get Usable Life - Years.
		@return Years of the usable life of the asset
	  */
	public int getUseLifeYears () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_UseLifeYears);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	/** Set Use units.
		@param UseUnits 
		Currently used units of the assets
	  */
	public void setUseUnits (int UseUnits)
	{
		set_ValueNoCheck (COLUMNNAME_UseUnits, Integer.valueOf(UseUnits));
	}

	/** Get Use units.
		@return Currently used units of the assets
	  */
	public int getUseUnits () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_UseUnits);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	/** Set Search Key.
		@param Value 
		Search key for the record in the format required - must be unique
	  */
	public void setValue (String Value)
	{
		set_Value (COLUMNNAME_Value, Value);
	}

	/** Get Search Key.
		@return Search key for the record in the format required - must be unique
	  */
	public String getValue () 
	{
		return (String)get_Value(COLUMNNAME_Value);
	}

	/** Set Version No.
		@param VersionNo 
		Version Number
	  */
	public void setVersionNo (String VersionNo)
	{
		set_Value (COLUMNNAME_VersionNo, VersionNo);
	}

	/** Get Version No.
		@return Version Number
	  */
	public String getVersionNo () 
	{
		return (String)get_Value(COLUMNNAME_VersionNo);
	}

	public BigDecimal getAccumDepreciation(Timestamp CalcDate) 
	{
		/*---------------------  Finding Asset Transactions ---------------------*/
		StringBuffer sql =  new StringBuffer();
		BigDecimal bDepAmt = new BigDecimal(0.0);
		BigDecimal bAccumDep = new BigDecimal(0.0);

		//Date tDateAcct;
    	sql.setLength(0);
        sql.append("SELECT tl.A_Asset_ID, tl.DeprAmt \n"
    	      + " FROM A_Asset_TransactionLine AS tl \n"  
    	      + " INNER JOIN A_Asset_Transaction AS t ON \n"
      		  + " t.A_Asset_Transaction_ID = tl.A_Asset_Transaction_ID \n"		
    	      + " WHERE (tl.A_Asset_ID = "+ get_ID()+
	            "\n OR tl.A_Asset2_ID = "+get_ID()+" ) "
    	      + "\n AND t.DateAcct <= '" + CalcDate+"'"
	    	  + "\n AND tl.isActive = 'Y'"); 
        
        PreparedStatement pstmt = null;
        ResultSet rs = null;
		pstmt = DB.prepareStatement (sql.toString(),null);
		rs = null;
		try {				
		  rs = pstmt.executeQuery();
		  while (rs.next()){
			  bDepAmt = rs.getBigDecimal("DeprAmt");
			  if (bDepAmt==null) continue;
			  if (rs.getInt("A_Asset_ID")==get_ID())
			     bAccumDep=bAccumDep.add(bDepAmt);
			  else
				 bAccumDep=bAccumDep.subtract(bDepAmt);
		  }
		} catch (Exception e) {
		  System.out.println("A_Asset_TransactionLine. Asset ID: "+get_ID()+" "+e);
		} finally {
			DB.close(rs, pstmt);
		    rs = null; pstmt = null;
		}
/*-------------------------------------  Finding Asset Transactions ------*/

		/*---------------------  Finding Asset Depreciation ---------------------*/
		BigDecimal bExpense = new BigDecimal(0.0);
    	sql.setLength(0);
        sql.append("SELECT A_Entry_Type, DateAcct, Expense, IsDepreciated"
        		+ ", PostingType, A_Period, A_Asset_ID"
        		+ " FROM A_Depreciation_Exp"
        		+ " WHERE A_Asset_ID = "+ get_ID()
        		+ " AND DateAcct <= '" + CalcDate+"'"
        		+ " AND A_Entry_Type = '"+ 
        		  X_A_Depreciation_Exp.A_ENTRY_TYPE_Depreciation+"'"); 
		pstmt = null;
		pstmt = DB.prepareStatement (sql.toString(),null);
		rs = null;
		try {				
		  rs = pstmt.executeQuery();
		  while (rs.next()){
			  bExpense = rs.getBigDecimal("Expense");
			  bAccumDep=bAccumDep.add(bExpense);
		  }
		} catch (Exception e) {
			   log.log(Level.SEVERE, "A_Depreciation_Exp. Asset ID: "+
		          get_ID()+" "+e);
		} finally {
			DB.close(rs, pstmt);
		    rs = null; pstmt = null;
		}
/*--------------------------------  Finding Asset Depreciation ------------*/		
		return bAccumDep;
	}

	public BigDecimal getAssetCost(Timestamp CalcDate) 
	{
		/*---------------------  Finding Asset Transactions ---------------------*/
		StringBuffer sql =  new StringBuffer();
		BigDecimal bAssetCost = new BigDecimal(0.0);
		BigDecimal bAssetAmt = new BigDecimal(0.0);

        sql.append("SELECT A_Asset_ID, AssetAmt"
    	      + " FROM A_Asset_TransactionLine"  
    	      + " WHERE (A_Asset_ID = "+ get_ID()+
    	            " OR A_Asset2_ID = "+get_ID()+" ) "
    	      + " AND DateAcct <= '" + CalcDate+"'"
	    	  + " AND isActive = 'Y'"); 
        PreparedStatement pstmt = null;
        ResultSet rs = null;
		pstmt = DB.prepareStatement (sql.toString(),null);
		rs = null;
		try {				
		  rs = pstmt.executeQuery();
		  while (rs.next()){
			  bAssetAmt = rs.getBigDecimal("AssetAmt");
			  if (bAssetAmt==null) continue;
			  if (rs.getInt("A_Asset_ID")==get_ID())
			      bAssetCost=bAssetCost.add(bAssetAmt);
			  else
				  bAssetCost=bAssetCost.subtract(bAssetAmt);
		  }
		} catch (Exception e) {
		  System.out.println("A_Asset_TransactionLine. Asset ID: "+get_ID()+" "+e);
		} finally {
			DB.close(rs, pstmt);
		    rs = null; pstmt = null;
		}
/*-------------------------------------  Finding Asset Transactions ------*/
		if (bAssetCost == null)	 return Env.ZERO;		
		return bAssetCost;
	}

	
	/** Get BPartner (Agent).
	@return Business Partner (Agent or Sales Rep)
  */
	public int getC_BPartnerSR_ID(Timestamp CalcDate)
    {
		StringBuffer sql =  new StringBuffer(
           "SELECT MAX(C_BPartnerSR_ID) FROM A_InternalMovement"
            +" WHERE A_Asset_ID = "+get_ID() 
			+" AND isActive = 'Y'" 
		    +" AND DateMoved = ( SELECT MAX(DateMoved)"
		    	+" FROM A_InternalMovement"
		    	+" WHERE A_Asset_ID = "+get_ID()
		    	+" AND DateMoved <= '" + CalcDate+"'"
		    	+" AND isActive = 'Y' )");
		int C_BPartnerSR_ID = DB.getSQLValue(get_TrxName(), sql.toString());
        if (C_BPartnerSR_ID<1) C_BPartnerSR_ID=getC_BPartnerSR_ID();
		return C_BPartnerSR_ID;	
	}

	public BigDecimal getAssetDepCorr() 
	{
		BigDecimal bAssetDepCorr = new BigDecimal(0.0);
		StringBuffer sql =  new StringBuffer(
				"SELECT A_Depreciation_Manual_Amount "
    	      + " FROM A_Asset_Acct"  
    	      + " WHERE A_Asset_ID = "+ get_ID()
	    	  + " AND isActive = 'Y'"); 
        PreparedStatement pstmt = null;
        ResultSet rs = null;
		pstmt = DB.prepareStatement(sql.toString(),null);
		rs = null;
		try {				
		  rs = pstmt.executeQuery();
		  while (rs.next()){
			  bAssetDepCorr = rs.getBigDecimal(1);
		  }
		} catch (Exception e) {
		  System.out.println("A_Asset_Acct. Asset ID: "+get_ID()+" "+e);
		} finally {
			DB.close(rs, pstmt);
		    rs = null; pstmt = null;
		}
		if (bAssetDepCorr == null) return Env.ZERO;		
		return bAssetDepCorr;
	}
	
	
	public BigDecimal getAssetDepForCost(Timestamp CalcDate) 
	{
		BigDecimal bAssetDepCost = getAssetCost(CalcDate).subtract(getAssetDepCorr());
		if (bAssetDepCost == null)	 return Env.ZERO;		
		return bAssetDepCost;
	}
	
	/** Transfer to New BPartner (Agent).
  */
	public int TransferTo(String DocNo, Timestamp CalcDate, int C_BPartnerSR_ID, String Description, int A_Location_ID)
    {
		if (C_BPartnerSR_ID == 0)
			throw new IllegalArgumentException("No Record");
		//
		int no = 0;
		String sql = "SELECT A_InternalMovement_ID FROM A_InternalMovement "
		+" WHERE A_Asset_ID = "+get_ID()
		+"  AND DateMoved = '"+CalcDate+"'";
		
        PreparedStatement pstmt = null;
        ResultSet rs = null;
		pstmt = DB.prepareStatement(sql,get_TrxName());
		rs = null;
		try {				
		  rs = pstmt.executeQuery();
		  while (rs.next()){
			  no = rs.getInt(1);
		  }
		} catch (Exception e) {
		  System.out.println("A_InternalMovement. Asset ID: "+get_ID()+" "+e);
		} finally {
			DB.close(rs, pstmt);
		    rs = null; pstmt = null;
		}
		
		if (no>0) return no;
		
		if (Description==null||Description.length()<3) {
			sql = "SELECT Name FROM HRM_Order" 
				  +" WHERE HRM_OrderType = '1'"
				  +" AND HRM_Number = '"+DocNo+"'"
				  +" AND HRM_Order_ID IN" 
					+" (  SELECT HRM_Order_ID FROM HRM_Employee"
						+" WHERE C_BPartner_ID = "+C_BPartnerSR_ID+")";
			pstmt = null;
			rs = null;
			try
			{
				pstmt = DB.prepareStatement(sql, get_TrxName());
				rs = pstmt.executeQuery();
				while (rs.next())
					{
						Description = rs.getString(1);
					}
				}
				catch (SQLException e)
				{
					log.log(Level.SEVERE, sql, e);
					return -1;
				}
				finally {
					DB.close(rs, pstmt);
					rs = null; pstmt = null;
				}
			
		}
			
		int recordID = MSequence.getNextID (Env.getAD_Client_ID(Env.getCtx())
				 , "A_InternalMovement", get_TrxName());
		sql = "INSERT INTO A_InternalMovement "
		+" (A_InternalMovement_ID, AD_Client_ID, AD_Org_ID,"
		+"IsActive, Created, CreatedBy, Updated, UpdatedBy,"
		+ "A_Asset_ID, DateMoved, Description, C_BPartnerSR_ID, DocumentNo, A_Location_ID)"
		+" VALUES ("+recordID+","+Env.getAD_Client_ID(Env.getCtx())+","
		+Env.getAD_Org_ID(Env.getCtx())+",'Y',SysDate,"+Env.getAD_User_ID(Env.getCtx())
		+",SysDate,"+Env.getAD_User_ID(Env.getCtx())+","+get_ID()+
		",'"+CalcDate+"','"+Description+"',"+C_BPartnerSR_ID+",'"+DocNo+"'"+" , "+A_Location_ID+")";
		no = DB.executeUpdate(sql, get_TrxName());
		if (no>0) {
			Timestamp currdate = new Timestamp(System.currentTimeMillis());
			X_A_Asset asset = new X_A_Asset (getCtx(), get_ID(), get_TrxName());
			int bpsr = asset.getC_BPartnerSR_ID(currdate);
			asset.setC_BPartnerSR_ID(bpsr);
			if(A_Location_ID !=0)
				asset.setA_Location_ID(A_Location_ID);
			asset.save();
		}
		return recordID;
	}

	public int getA_Asset_Transaction_ID(int C_Invoice_ID)
    {
		StringBuffer sql =  new StringBuffer(
			"SELECT A_Asset_Transaction_ID FROM A_Asset_Transaction "
			+ " WHERE C_Invoice_ID = "+C_Invoice_ID
            + " AND isActive = 'Y'");
		int iAT_ID=0;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
		pstmt = DB.prepareStatement (sql.toString(),null);
		rs = null;
		try {				
		  rs = pstmt.executeQuery();
		  while (rs.next()){
			  iAT_ID = rs.getInt(1);
		  }
		} catch (Exception e) {
		  System.out.println("A_Asset_Transaction. Asset ID: "+get_ID()+" "+e);
		} finally {
			DB.close(rs, pstmt);
		    rs = null; pstmt = null;
		}
		return iAT_ID;	
	}

	public int getA_Asset_TransactionLine_ID(int C_InvoiceLine_ID)
    {
		StringBuffer sql =  new StringBuffer(
			"SELECT A_Asset_TransactionLine_ID FROM A_Asset_TransactionLine "
			+ " WHERE C_InvoiceLine_ID = "+C_InvoiceLine_ID
            + " AND isActive = 'Y'");
		int iATL_ID=0;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
		pstmt = DB.prepareStatement (sql.toString(),null);
		rs = null;
		try {				
		  rs = pstmt.executeQuery();
		  while (rs.next()){
			  iATL_ID = rs.getInt(1);
		  }
		} catch (Exception e) {
		  System.out.println("A_Asset_TransactionLine. Asset ID: "+get_ID()+" "+e);
		} finally {
			DB.close(rs, pstmt);
		    rs = null; pstmt = null;
		}
		return iATL_ID;	
	}

	public int getA_Depreciation_Workfile_ID()
    {
		StringBuffer sql =  new StringBuffer(
			"SELECT A_Depreciation_Workfile_ID FROM A_Depreciation_Workfile "
			+ " WHERE PostingType = 'A' "
			+ " AND A_Asset_ID = "+ get_ID()
		    + " AND isActive = 'Y'");
		int iDW_ID=0;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
		pstmt = DB.prepareStatement (sql.toString(),null);
		rs = null;
		try {				
		  rs = pstmt.executeQuery();
		  while (rs.next()){
			  iDW_ID = rs.getInt(1);
		  }
		} catch (Exception e) {
		  System.out.println("A_Depreciation_Workfile. Asset ID: "+get_ID()+" "+e);
		} finally {
			DB.close(rs, pstmt);
		    rs = null; pstmt = null;
		}
		return iDW_ID;	
	}
	
	public int getAcctValue(String Value)
    {
		StringBuffer sql =  new StringBuffer(
			"SELECT "+Value+" FROM A_Asset_Acct "
			+ " WHERE A_Asset_ID = "+ get_ID()
		    + " AND isActive = 'Y'");
		int iAV=0;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
		pstmt = DB.prepareStatement (sql.toString(),null);
		rs = null;
		try {				
		  rs = pstmt.executeQuery();
		  while (rs.next()){
			  iAV = rs.getInt(1);
		  }
		} catch (Exception e) {
		  System.out.println("A_Asset_Acct. Asset ID: "+get_ID()+" "+e);
		} finally {
			DB.close(rs, pstmt);
		    rs = null; pstmt = null;
		}
		if (iAV>0) return iAV;
		
		sql.setLength(0);
		sql.append("SELECT "+Value+" FROM A_Asset_Group_Acct"
		    	+" WHERE A_Asset_Group_ID  = " +getA_Asset_Group_ID()	    		
		        +" AND isActive = 'Y'");
		pstmt = null;
		pstmt = DB.prepareStatement (sql.toString(),null);
		rs = null;
		try {				
			rs = pstmt.executeQuery();
		    while (rs.next()){
		    	  iAV = rs.getInt(1);
		    }
		} catch (Exception e) {
			System.out.println("A_Asset_Group_Acct. Asset ID: "+get_ID()+" "+e);
		} finally {
			DB.close(rs, pstmt);
			rs = null; pstmt = null;
		}
		return iAV;	
	}
	
	public BigDecimal getDepPost(Timestamp CalcDateFrom, Timestamp CalcDateTo) 
	{
		/*---------------------  Finding Asset Depreciation ---------------------*/
		BigDecimal bExpense = new BigDecimal(0.0);
		BigDecimal bDepPost = new BigDecimal(0.0);
		StringBuffer sql =  new StringBuffer(
				"SELECT A_Entry_Type, DateAcct, Expense, IsDepreciated"
        		+ ", PostingType, A_Period, A_Asset_ID"
        		+ " FROM A_Depreciation_Exp"
        		+ " WHERE A_Asset_ID = "+ get_ID()
        		+ " AND DateAcct >= '" + CalcDateFrom+"'"
        		+ " AND DateAcct <= '" + CalcDateTo+"'"
        		+ " AND A_Entry_Type = '"+ 
        		  X_A_Depreciation_Exp.A_ENTRY_TYPE_Depreciation+"'"); 
        PreparedStatement pstmt = null;
        ResultSet rs = null;
		pstmt = DB.prepareStatement (sql.toString(),null);
		rs = null;
		try {				
		  rs = pstmt.executeQuery();
		  while (rs.next()){
			  bExpense = rs.getBigDecimal("Expense");
			  if (bExpense==null) continue;
			  bDepPost=bDepPost.add(bExpense);
		  }
		} catch (Exception e) {
			   log.log(Level.SEVERE, "A_Depreciation_Exp. Asset ID: "+
		          get_ID()+" "+e);
		} finally {
			DB.close(rs, pstmt);
		    rs = null; pstmt = null;
		}
		sql =  new StringBuffer(
				"SELECT DeprAmt "
        		+ " FROM A_Asset_TransactionLine AS tl"
				+ " INNER JOIN A_Asset_Transaction AS t ON "
        		+ " t.A_Asset_Transaction_ID = tl.A_Asset_Transaction_ID"		
        		+ " WHERE tl.A_Asset_ID = "+ get_ID()
        		+ " AND t.DateAcct >= '" + CalcDateFrom+"'"
        		+ " AND t.DateAcct <= '" + CalcDateTo+"'"
        		+ " AND tl.AssetAmt = 0"
        		+ " AND tl.DeprAmt IS NOT NULL"); 
        pstmt = null;
        rs = null;
		pstmt = DB.prepareStatement (sql.toString(),null);
		rs = null;
		try {				
		  rs = pstmt.executeQuery();
		  while (rs.next()){
			  bExpense = rs.getBigDecimal(1);
			  if (bExpense==null) continue;
			  bDepPost=bDepPost.add(bExpense);
		  }
		} catch (Exception e) {
			   log.log(Level.SEVERE, "A_Asset_TransactionLine. Asset ID: "+
		          get_ID()+" "+e);
		} finally {
			DB.close(rs, pstmt);
		    rs = null; pstmt = null;
		}
		
		if (bDepPost == null)	 return Env.ZERO;		
		return bDepPost;
	}

	public BigDecimal getBalanceCost(Timestamp CalcDate) 
	{
		/*---------------------  Finding Asset Depreciation ---------------------*/
		BigDecimal bExpense = new BigDecimal(0.0);
		BigDecimal bCost = new BigDecimal(0.0);
		BigDecimal bBalance = new BigDecimal(0.0);
		StringBuffer sql =  new StringBuffer(
				"SELECT AssetAmt, DeprAmt, A_Asset2_ID "
        		+ " FROM A_Asset_TransactionLine AS tl"
				+ " INNER JOIN A_Asset_Transaction AS t ON "
        		+ " t.A_Asset_Transaction_ID = tl.A_Asset_Transaction_ID"		
        		+ " WHERE (tl.A_Asset_ID ="+ get_ID()+" OR tl.A_Asset2_ID ="+get_ID()+")"
        		+ " AND t.DateAcct <= '" + CalcDate+"'");
        PreparedStatement pstmt = DB.prepareStatement (sql.toString(),null);
        ResultSet rs = null;
		
		try {				
		  rs = pstmt.executeQuery();
		  while (rs.next()){
			  bCost = rs.getBigDecimal(1);
			  bExpense = rs.getBigDecimal(2);
			  if (get_ID()==rs.getInt(3)) {
				  if (bCost!=null) bBalance=bBalance.subtract(bCost);
				  if (bExpense!=null) bBalance=bBalance.add(bExpense);
			  } else {
				  if (bCost!=null) bBalance=bBalance.add(bCost);
				  if (bExpense!=null) bBalance=bBalance.subtract(bExpense);
			  }
		  }
		} catch (Exception e) {
			   log.log(Level.SEVERE, "A_Asset_TransactionLine. Asset ID: "+
		          get_ID()+" "+e);
		} finally {
			DB.close(rs, pstmt);
		    rs = null; pstmt = null;
		}
		sql =  new StringBuffer(
				"SELECT A_Entry_Type, DateAcct, Expense, IsDepreciated"
        		+ ", PostingType, A_Period, A_Asset_ID"
        		+ " FROM A_Depreciation_Exp"
        		+ " WHERE A_Asset_ID = "+ get_ID()
        		+ " AND DateAcct <= '" + CalcDate+"'"
        		+ " AND A_Entry_Type = '"+ 
        		  X_A_Depreciation_Exp.A_ENTRY_TYPE_Depreciation+"'"); 
        pstmt = null;
        rs = null;
		pstmt = DB.prepareStatement (sql.toString(),null);
		rs = null;
		try {				
		  rs = pstmt.executeQuery();
		  while (rs.next()){
			  bExpense = rs.getBigDecimal("Expense");
			  if (bExpense==null) continue;
			  bBalance=bBalance.subtract(bExpense);
		  }
		} catch (Exception e) {
			   log.log(Level.SEVERE, "A_Depreciation_Exp. Asset ID: "+
		          get_ID()+" "+e);
		} finally {
			DB.close(rs, pstmt);
		    rs = null; pstmt = null;
		}
		
		if (bBalance == null)	 return Env.ZERO;		
		return bBalance;
	}
	
}